package com.ruoyi.web.controller.map;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.map.domain.PersonSupplySurvey;
import com.ruoyi.map.service.IPersonSupplySurveyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 个人供给调查Controller
 *
 * @author dihang
 * @date 2023-08-16
 */
@Api(value = "小程序个人供给申请",tags = {"小程序个人供给申请"})
@RestController
@RequestMapping("/map/survey")
public class PersonSupplySurveyController extends BaseController
{
    @Autowired
    private IPersonSupplySurveyService personSupplySurveyService;


    /**
     * 查询个人供给的各个申请支持方式的数量（柱状图）
     * @return
     */
    @ApiOperation(value = "查询单位供给的各个申请支持方式的数量（柱状图）")
    @GetMapping("/supportWay")
    public List<Map<String ,Object>>countBySupportWay(){
        List<Map<String, Object>> maps = personSupplySurveyService.countBySupportWay();
        return maps;
    }


    /**查询个人供给的各个支持项目类型的数量（饼状图）
     *
     * @return
     */
    @ApiOperation(value = "查询单位供给的各个支持项目类型的数量（饼状图）")
    @GetMapping("/projectType")
    public List<Map<String ,Object>> countBySupportType() {
        List<Map<String, Object>> result = personSupplySurveyService.countByProjectType();
        return result;
    }



    /**
     * 查询个人供给调查列表
     */
    @ApiOperation(value = "查询个人供给调查列表")
    @PreAuthorize("@ss.hasPermi('map:survey:list')")
    @GetMapping("/list")
    public TableDataInfo list(PersonSupplySurvey personSupplySurvey)
    {
        startPage();
        List<PersonSupplySurvey> list = personSupplySurveyService.selectPersonSupplySurveyList(personSupplySurvey);
        return getDataTable(list);
    }

    /**
     * 导出个人供给调查列表
     */
    @PreAuthorize("@ss.hasPermi('map:survey:export')")
    @Log(title = "个人供给调查", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PersonSupplySurvey personSupplySurvey)
    {
        List<PersonSupplySurvey> list = personSupplySurveyService.selectPersonSupplySurveyList(personSupplySurvey);
        ExcelUtil<PersonSupplySurvey> util = new ExcelUtil<PersonSupplySurvey>(PersonSupplySurvey.class);
        util.exportExcel(response, list, "个人供给调查数据");
    }

    /**
     * 获取个人供给调查详细信息
     */
    @ApiOperation(value = "获取个人供给调查详细信息")
    @PreAuthorize("@ss.hasPermi('map:survey:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(personSupplySurveyService.getById(id));
    }

    /**
     * 新增个人供给调查
     */
    @ApiOperation(value = "新增个人供给申请调查")
    @PreAuthorize("@ss.hasPermi('map:survey:add')")
    @Log(title = "个人供给调查", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PersonSupplySurvey personSupplySurvey) {

        return toAjax(personSupplySurveyService.save(personSupplySurvey));
    }

    /**
     * 修改个人供给调查
     */
    @PreAuthorize("@ss.hasPermi('map:survey:edit')")
    @Log(title = "个人供给调查", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PersonSupplySurvey personSupplySurvey) {
        return toAjax(personSupplySurveyService.updateById(personSupplySurvey));
    }

    /**
     * 删除个人供给调查
     */
    @PreAuthorize("@ss.hasPermi('map:survey:remove')")
    @Log(title = "个人供给调查", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(personSupplySurveyService.removeByIds(Arrays.asList(ids)));
    }
}
